using GDPView.Database;
using GDPView.Services;
using Microsoft.EntityFrameworkCore;
using System;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Configuration.AddJsonFile("appsettings.json");
builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("DbContext"))
);

builder.Services.AddTransient<ISampleDataRepository, SampleDataRepository>();
builder.Services.AddTransient<IGDPDataRepository, GDPDataRepository>();
builder.Services.AddTransient<IGDPGrowthRateDataRepository, GDPGrowthRateDataRepository>();

builder.Services.AddCors(options =>
{
    options.AddPolicy("cors", builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); });
});

builder.Services.AddControllers();

var app = builder.Build();

app.UseAuthorization();

app.MapControllers();

app.UseCors("cors");

app.Run();
